import { ApiCall } from "tsrpc";
import { ReqRandom_talent, ResRandom_talent } from "../../../../shared/master/bag/function/PtlRandom_talent";
import app, { xlsxCfgNames } from "../../../../app";
import { player } from "../../../../model/fight/body/player";
import { template } from "../../../../shared/master/MsgAction";

export default async function (call: ApiCall<ReqRandom_talent, ResRandom_talent>) {
    call.succ({})
    let user = call.req._player as player;

    if (user.get_battle()) {
        user.sendMsg(template.default, '战斗中无法重置天赋.')
        return;
    }
    let res = user.check_wallet(0,0,[{id:'prop-4',v:1}],false,'重置天赋',true);
    if(!res.state){
        return;
    }

    let tables = app.xlsxCfgMap.get(xlsxCfgNames.天赋表) as Map<string, any>;
    let list = [...tables.values()]
    let idx = app.random(0, list.length - 1);
    user.reset_talent(list[idx].id);


    user.update_attributes();
    user.sendMsg(template.panel_talent,user.get_panel_talent())
}